/****************************************************************************
 * Copyright (c) 2008, 2009 Andreas Unger and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Andreas Unger - initial API and implementation 
 ****************************************************************************/

package org.eclipselabs.damos.library.signal.ui.editparts;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipselabs.damos.diagram.ui.editparts.LabeledRectangularBlockEditPart;
import org.eclipselabs.damos.dml.Block;
import org.eclipselabs.damos.dml.DMLPackage;
import org.eclipselabs.damos.dml.ExplicitOutputDataTypeSpecification;
import org.eclipselabs.damos.dml.OutputDataTypeSpecification;
import org.eclipselabs.damos.expressions.util.ExpressionsUtil;

/**
 * @author Andreas Unger
 *
 */
public class DataTypeConversionEditPart extends LabeledRectangularBlockEditPart {

	/**
	 * @param view
	 */
	public DataTypeConversionEditPart(View view) {
		super(view);
	}

	protected String getLabel() {
		String dataTypeString = "";
		Block block = (Block) resolveSemanticElement();
		if (block != null) {
			OutputDataTypeSpecification spec = block.getOutputDataTypeSpecification();
			if (spec instanceof ExplicitOutputDataTypeSpecification) {
				dataTypeString = ExpressionsUtil.dataTypeToString(((ExplicitOutputDataTypeSpecification) spec).getDataType());
			} else {
				dataTypeString = "Inherit";
			}
		}
		return "(" + dataTypeString + ")";
	}
	
	protected void handleNotificationEvent(Notification notification) {
		if (notification.getFeature() == DMLPackage.Literals.COMPONENT__OUTPUT_DATA_TYPE_SPECIFICATION) {
			refreshLabel();
		}
		super.handleNotificationEvent(notification);
	}

}
